//
//  LGPhotoView.m
//  微博
//
//  Created by MS on 15-12-24.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGPhotoView.h"
#import "UIImageView+WebCache.h"
#import "UIView+Frame.h"
@interface LGPhotoView ()

@property (nonatomic,weak) UIImageView * gifView;

@end

@implementation LGPhotoView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.contentMode = UIViewContentModeScaleAspectFill;
        self.clipsToBounds =YES;
        self.userInteractionEnabled = YES;
        
        UIImageView * gifView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"timeline_image_gif"]];
        [self addSubview:gifView];
        self.gifView = gifView;
        
    }
    return  self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.gifView.x = self.width - self.gifView.width;
    self.gifView.y = self.height - self.gifView.height;
    
}

-(void)setPhoto:(LGPhoto *)photo
{
    _photo = photo;
    
    [self sd_setImageWithURL:photo.thumbnail_pic  placeholderImage:[UIImage imageNamed:@"timeline_image_placeholder"]];

    if ([photo.thumbnail_pic.absoluteString hasSuffix:@".gif"]) {
        self.gifView.hidden = NO;
    }
    else
    {
        self.gifView.hidden = YES;
    }
}

@end
